package algebra.op;

import java.util.HashSet;
import java.util.Set;

import option.QueryKeywords;

import utils.Display;

import kb.DescriptionLogicsKB;
import entities.role.Role;

public class PrimaryOP extends AlgebraicOP {

	private final DescriptionLogicsKB kb;

	// public PrimaryOP(){
	// this.kb = null;
	// }

	public PrimaryOP(DescriptionLogicsKB kb) {
		this.kb = kb;
	}

	@Override
	public boolean isPure() {
		return true;
	}

	@Override
	public String toString() {
		return Display.QPIUNICODE;
	}

	@Override
	public String toSerializedString() {
		return " (" + QueryKeywords.QPI + ") ";
	}

	@Override
	public DescriptionLogicsKB getPlanEvalKB() {
		if (this.kb == null) {
			System.err
					.println("WARNING: The knowledge base for evaluating primary cache/index is empty.");
		}
		return this.kb;
	}

	// public void setPlanEvalKB(DescriptionLogicsKB kb){
	// this.kb = kb;
	// }

	@Override
	public Set<Role> extractFeatures() {
		Set<Role> fs = new HashSet<Role>();
		return fs;
	}

	@Override
	public Set<String> extractConstants() {
		Set<String> ks = new HashSet<String>();
		return ks;
	}

	@Override
	public boolean isLeaf() {
		return true;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((kb == null) ? 0 : kb.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof PrimaryOP))
			return false;
		PrimaryOP other = (PrimaryOP) obj;
		if (kb == null) {
			if (other.kb != null)
				return false;
		} else if (!kb.equals(other.kb))
			return false;
		return true;
	}

	// PK always needs some K
	@Override
	public AlgebraicOP getKFreeVersion() {
		return null;
	}

}
